package com.easpeed.comon.consts

import android.util.Log;
import com.bigyu.utils.Logger
import com.easpeed.elevator.bean.EventThreshold

/**
 * Created by bigyu on 2025-02-11 17:15
 * com.easpeed.comon.consts
 */
object ConstsOpticalData {
    @JvmField
    var options: Array<String> = arrayOf("一级", "二级", "三级")


    /**
     * 事件阈值
     */
    @JvmStatic
    private var eventThreshold = EventThreshold()

    @JvmStatic
    fun setEventThreshold(threshold: EventThreshold?) {
        if (threshold == null) {
            return
        }
        eventThreshold = threshold
    }

    @JvmStatic
    fun getThreshold(): EventThreshold {
        return eventThreshold
    }


    fun getLevel(level: String?): String {
        try {
            val level = ConstsOpticalData.options.getOrNull(level!!.toInt())
            return level ?: ""
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return ""
    }

    fun getLevelIndex(level: String?): Int {
        try {
            return ConstsOpticalData.options.indexOf(level)
        } catch (e: Exception) {
            e.printStackTrace()
            return 0
        }
    }


    /**
     * 波长数据
     */
    @JvmField
    val defaultDataBcMap: HashMap<String, String> = LinkedHashMap()
    val dataBcMap: HashMap<String, String> = LinkedHashMap()

    /**
     * 波长
     */
    @JvmStatic
    fun getDefaultBc(): String {
        return dataBcMap["1310"] ?: "1e05"
    }

    @JvmStatic
    fun getDefaultBcKey(): String {
        return "1310"
    }

    @JvmStatic
    fun getBc(key: String?): String {
        return dataBcMap[key] ?: getDefaultBc()
    }

    fun getBcList(): List<String> {
        return dataBcMap.keys.toList()
    }


    //滤波数据
    @JvmField
    val dataLb: List<String> = mutableListOf("0", "80", "100", "120", "150")


    //采集范围数据
    @JvmField
    val dataCjfw: MutableList<String> = mutableListOf("500", "1000", "2500", "5000", "10000", "25000", "50000", "100000")

    @JvmField
    val dataMcsj: List<String> = mutableListOf("3", "5", "10", "30", "50")

    //脉冲宽度数据
    @JvmField
    val dataMcsjDvs: List<String> = mutableListOf("50", "100", "200")

    //测试时间
    @JvmField
    val dataCssj: List<String> = mutableListOf("5", "10", "30", "60")


    @JvmStatic
    fun getMckdData(cjfw: String): List<String> {
        return dataCjfwMap[cjfw] ?: mutableListOf()
    }

    //脉冲宽度数据
    @JvmField
    val dataCjfwMap: HashMap<String, List<String>> = LinkedHashMap()


    @JvmStatic
    fun reloadWaveLength(list: List<String>) {
        dataBcMap.clear()
        defaultDataBcMap.filter {
            list.contains(it.key)
        }.let {
            dataBcMap.putAll(it)
        }

        Logger.e("TAG", "====>最新的波长数据: $dataBcMap")
    }

    init {
        dataCjfwMap.clear()
        dataCjfwMap["500"] = mutableListOf("3", "5", "10", "30", "50")
        dataCjfwMap["1000"] = mutableListOf("3", "5", "10", "30", "50")
        dataCjfwMap["2500"] = mutableListOf("5", "10", "30", "50", "100")
        dataCjfwMap["5000"] = mutableListOf("10", "30", "50", "100", "300")
        dataCjfwMap["10000"] = mutableListOf("30", "50", "100", "300", "500")
        dataCjfwMap["25000"] = mutableListOf("50", "100", "300", "500", "1000")
        dataCjfwMap["50000"] = mutableListOf("100", "300", "500", "1000", "3000")
        dataCjfwMap["100000"] = mutableListOf("300", "500", "1000", "3000", "5000")


        defaultDataBcMap.clear()
        defaultDataBcMap["1310"] = "1e05"
        defaultDataBcMap["1550"] = "0e06"
        defaultDataBcMap["1625"] = "5906"

        dataBcMap.clear()
        dataBcMap.putAll(defaultDataBcMap)


        if (CustomSetting.addTestCsfw) {
            dataCjfw.add("150000")
            dataCjfwMap["150000"] = mutableListOf("500", "1000", "3000", "5000", "1000")
        }
    }
}